<?php
	if($_COOKIE['user_id']!='admin')
		Header("location:main.php");
	
	require_once('start_session.php');
	//setcookie('user_id', 'famous');
	require_once('header.php');
	require_once('db_connect.php');
	require_once('global_vars.php');
	//require_once('search_bar.php');
	require_once('admin_menu.php');	
?>
<link href="./css/tables.css" rel="stylesheet" type="text/css">
<div id="user_info">
<h3>사용자 정보</h3>
<table border="0" cellspacing="0" cellpadding="0">
<thead>
	<tr>
		<th scope="col" width="4%">아이디</th>
		<th scope="col" width="4%">이름</th>
		<th scope="col" width="3%">성별</th>
		<th scope="col" width="3%">나이</th>
		<th scope="col" width="5%">학력</th>
		<th scope="col" width="8%">전화번호</th>
		<th scope="col" width="6%">생년월일</th>
		<th scope="col" width="7%">이메일주소</th>
		<th scope="col" width="10%">주소</th>
		<th scope="col" width="5%">참여횟수</th>
		<th scope="col" width="5%">작성횟수</th>	
		<th scope="col" width="5%">카테고리</th>	
		<th scope="col" width="7%">키워드</th>	
	</tr>
</thead>
<tbody>
	<?	
	$sql="SELECT * FROM member where id <> 'admin'";
	//$sql="SELECT * FROM member INNER JOIN category_mem ON member.id = category_mem.mem_id";
	$result=mysqli_query($conn,$sql);
	while($row=mysqli_fetch_array($result))
	{
		echo "<tr>";
		echo "<td>".$row[id]."</td>";
		$id=$row[id];
		echo "<td>".$row[name]."</td>";
		if($row[gender]==1)
			echo "<td>"."남"."</td>";
		if($row[gender]==2)
			echo "<td>"."여"."</td>";
		echo "<td>".$row[age]."</td>";
		switch($row[edulevel])
		{
			case 1:	echo "<td>"."중졸 이하"."</td>";
			break;
			case 2:	echo "<td>"."고졸"."</td>";
			break;
			case 3:	echo "<td>"."초대졸"."</td>";
			break;
			case 4:	echo "<td>"."대졸"."</td>";
			break;
			case 5:	echo "<td>"."대학원졸 이상"."</td>";
			break;
		}			
		echo "<td>".$row[phone]."</td>";
		echo "<td>".$row[birth]."</td>";
		echo "<td>".$row[email]."</td>";
		echo "<td>".$row[addr]."</td>";
		echo "<td>".$row[answer_count]."</td>";
		echo "<td>".$row[make_count]."</td>";
		echo "<td>";

		$sql="SELECT * FROM category_mem WHERE mem_id ='$row[id]'";
		$result2=mysqli_query($conn,$sql);		
		$length = mysqli_num_rows($result2);
		$i=1;
		while(1)
		{
			$row=mysqli_fetch_array($result2);
			if($i < $length)
				echo $row[category].",";
			else
			{
				echo $row[category];
				break;
			}
			$i++;	
			
		}
		echo "</td>";
		
		$sql="SELECT * FROM keyword_mem WHERE mem_id ='$id'";
		$result2=mysqli_query($conn,$sql);
		echo "<td>";
		$length = mysqli_num_rows($result2);
		echo $row[id];
		$i=1;
		while(1)
		{
			$row=mysqli_fetch_array($result2);
			if($i < $length)
				echo $row[keyword].",";
			else
			{
				echo $row[keyword];
				break;
			}
			$i++;	
			
		}		
		echo "</td>";
			
		
	}		
		
?>
</tbody>
</table>
</div>
<div id="footer">
</div>
</div>
</body>
</html>